package moddb.resource;

//import java.sql.*;
import moddb.schema.*;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import javax.ws.rs.core.Response.*;
import moddb.Backend;
import java.util.LinkedList;

@Path("/rubyinterface")
public class MiddletierRubyResource {
  
  /*
   * Get middle_tier interface for Ruby/Shoes
   */
   @GET
   @Produces("text/plain")
   @Path("{version}")
   public String getRubyInterface(@PathParam("version") String version) {

      LinkedList<File> ifs = Backend.getFiles("^admin$", "^middletier-v\\d+\\.\\d+\\.rb", 100, 0);
      
      for (File file : ifs) {
        
        String file_ver = file.name.substring("middletier-v".length(), file.name.lastIndexOf("."));
        System.out.println("RubyInterface file version: " + file_ver);
        if (file_ver.equals(version)) {
          return new String(Backend.getFileData("admin", Integer.parseInt(file.id)));
        }
      }
      
      return null;
   }
   
   
}
